Passed
Pull Request — master (#2)
by
unknown
03:05
created

index.js ➔ ???   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 57
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3.2341

Importance

Changes 0
Metric Value
cc 3
eloc 31
nc 3
nop 2
dl 0
loc 57
ccs 19
cts 27
cp 0.7037
crap 3.2341
rs 9.1359
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ ... ➔ ??? 0 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1 2
import mixin from './mixin'
2 2
import { setPageTitle } from './page-title'
3 2
import { setup as setupRouter } from './router'
4 2
import {safeString} from './utils'
5
6 2
const install = (Vue, options = {}) => {
7
  // prevent double install
8
  /* istanbul ignore next */
9
  if (install.installed) return
10 5
  install.installed = true
11
12
  // title state
13 5
  const $page = {
14
    title: '',
15
    prefix: safeString(options.prefix),
16
    suffix: safeString(options.suffix)
17
  }
18
19 5
  const setTitle = value => {
20 10
    setPageTitle(value, options)
21 10
    $page.title = value
22
  }
23
24 5
  const setPrefix = value => {
25
    options.prefix = value
26
    setTitle($page.title)
27
  }
28
29 5
  const setSuffix = value => {
30
    options.suffix = value
31
    setTitle($page.title)
32
  }
33
34
  // make reactive title properties
35 5
  Vue.util.defineReactive($page, 'title', '')
36 5
  Vue.util.defineReactive($page, 'prefix', '')
37 5
  Vue.util.defineReactive($page, 'suffix', '')
38
39
  // add title elements to component context
40 5
  Object.defineProperty(Vue.prototype, '$title', {
41 21
    get: () => $page.title,
42 9
    set: value => setTitle(value)
43
  })
44
45 5
  Object.defineProperty(Vue.prototype, '$titlePrefix', {
46
    get: () => $page.prefix,
47
    set: value => setPrefix(value)
48
  })
49
50 5
  Object.defineProperty(Vue.prototype, '$titleSuffix', {
51
    get: () => $page.suffix,
52
    set: value => setSuffix(value)
53
  })
54
55
  // vue router support
56 5
  if (options.router) {
57 1
    setupRouter(setTitle, setPrefix, setSuffix, options)
58
  }
59
60
  // add global mixin
61 5
  Vue.mixin(mixin)
62
}
63
64 2
const VuePageTitle = { install }
65
66
export { install }
67
export default VuePageTitle
68